package com.suxin.datahub;

import com.suxin.datahub.core.BaseReaderWriter;
import com.suxin.datahub.database.ReaderWriterFactory;
import com.suxin.datahub.domain.DataSourceDomain;
import com.suxin.datahub.domain.DataSourceJob;
import com.suxin.datahub.enums.DbType;
import org.junit.Test;

import java.util.Objects;

/**
 * @Classname TestMain
 * @Description [ TestMain ]
 * @Author Tang
 * @Date 2020/11/9 17:08
 * @Created by ASUS
 */
public class TestMain {

    public static void main(String[] args) {

        DataSourceDomain dataSourceDomain01 = new DataSourceDomain();
        dataSourceDomain01.setName("test01");
        dataSourceDomain01.setUrl("jdbc:mysql://localhost:3306/test01?rewriteBatchedStatements=true&useSSL=false&allowMultiQueries=true&serverTimezone=GMT%2B8");
        dataSourceDomain01.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSourceDomain01.setUsername("root");
        dataSourceDomain01.setPassword("721000");
        dataSourceDomain01.setSql("select * from test01");
        dataSourceDomain01.setDbType(DbType.MYSQL);

//        System.out.println(JSON.toJSONString(dataSourceDomain01));

//        DataBaseMetaService metaService = DataBaseFactory.getMetaService(dataSourceDomain01);
//
//        metaService.getTables().forEach(System.out::println);
//
//        System.out.println(
//                metaService.getTableColumns("test01", "test01")
//        );

        DataSourceDomain dataSourceDomain02 = new DataSourceDomain();
        dataSourceDomain02.setName("test02");
        dataSourceDomain02.setUrl("jdbc:mysql://127.0.0.1:3306/test02?rewriteBatchedStatements=true&useSSL=false&allowMultiQueries=true&serverTimezone=GMT%2B8");
        dataSourceDomain02.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSourceDomain02.setUsername("root");
        dataSourceDomain02.setPassword("721000");
        dataSourceDomain02.setSql("insert into test01");
        dataSourceDomain02.setDbType(DbType.MYSQL);

        DataSourceJob dataSourceJob = new DataSourceJob();

        dataSourceJob.setReaderDataSource(dataSourceDomain01);
        dataSourceJob.setWriterDataSource(dataSourceDomain02);

        long execute = new BaseReaderWriter().execute(
                Objects.requireNonNull(ReaderWriterFactory.getReader(dataSourceJob)),
                Objects.requireNonNull(ReaderWriterFactory.getWriter(dataSourceJob))
        );

    }

    @Test
    public void test01(){
    }
}